package com.wanxi.app.controller.api;

import com.wanxi.domain.vo.Paging;
import com.wanxi.orderApi.OrderFeign;
import com.wanxi.domain.code.ResultCode;
import com.wanxi.domain.vo.OrderQueryVO;
import com.wanxi.domain.vo.OrderVO;
import com.wanxi.domain.vo.PlaceOrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author LiuYuRong
 * @Date 2022/1/18 8:55
 * @Version 1.0
 * @Description
 */

@RestController
public class OrderApi {
    /**
     * 用户获得自己的订单数据
     *
     * @param vo 查询条件，必须传入用户id
     * @return 这个用户的订单列表
     */
    @Autowired
    private OrderFeign orderFeign;
    @GetMapping("/order/orderApi/customer/getCustomerOrdersById/")
    List<OrderVO> getCustomerOrdersById(@RequestParam("userId") Long userId, Paging paging){
        return orderFeign.getCustomerOrdersById(userId, paging);
    }



    /**
     * 支付订单
     *
     * @param orderId 订单id
     * @return 是否成功提示
     */
    @PutMapping("/order/orderApi/pay/{orderId}")
    ResultCode payOrder(@PathVariable("orderId") long orderId){
        return orderFeign.payOrder(orderId);
    }

    /**
     * 下单
     *
     * @param order 订单下单所需项
     * @return 是否下单成功
     */
    @PostMapping("/order/orderApi/placeOrder/")
    ResultCode submitOrder(@RequestBody PlaceOrderVO order){
        return orderFeign.addOrder(order);
    }


    /**
     * 用户收货
     *
     * @param orderId 订单id
     * @return 是否成功
     */
    @PutMapping("/order/orderApi/received/{orderId}")
    ResultCode receive(@PathVariable("orderId") long orderId){
        return orderFeign.receive(orderId);
    }

    /**
     * 取消订单
     *
     *
     * @param orderId 订单id
     * @return 是否操作成功提示
     */
    @PutMapping("/order/orderApi/handlecancel/{orderId}")
    ResultCode handleCancel(@PathVariable("orderId") long orderId){
        return orderFeign.handleCancel(orderId);
    }

    @PutMapping("/order/orderApi/autocancel/{orderId}")
    ResultCode autoCancel(@PathVariable("orderId") long orderId){
        return orderFeign.autoCancel(orderId);
    }

    /**
     * 删除订单，修改订单状态为不可见，is_delete字段 设为1
     *
     * @param orderId 订单id
     * @return 是否操作成功提示
     */
    @DeleteMapping("/order/orderApi/delete/{orderId}")
    ResultCode deleteOrderById(@PathVariable("orderId") long orderId){
        return orderFeign.deleteOrderById(orderId);
    }

    /**
     * 提交订单前的工作，包括计算订单总金额和优惠金额（如果使用了优惠券）
     *
     * @param orderVO 订单视图
     * @return 订单总金额和优惠金额（如果使用了优惠券）例如{“amount”:"152.00"}这种形式
     */
    @PostMapping("/order/orderApi/beforeSubmitOrder/")
    Map<String, Object> beforeSubmitOrder(@RequestBody PlaceOrderVO orderVO){
        return orderFeign.beforeSubmitOrder(orderVO);
    }
}
